﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using TestInterface;

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UserTestController : Controller
    {
        private readonly IEnumerable<IUserServices> _userServices = null;
        private readonly IUserServices _userServices1 = null;
        public UserTestController(IEnumerable<IUserServices> userServices, IUserServices userServices1)
        {
            _userServices = userServices;
            _userServices1 = userServices1;
        }
        /// <summary>
        /// autofac是可以取出一个接口类的所有实现类，然后通过遍历去找到你自己想要的(加上IEnumerable)
        /// </summary>
        /// <returns></returns>
        [HttpPost("test")]
        public string test()
        {
            string sum = "";
            foreach (var item in _userServices)
            {
                sum+=item.Test()+",";
            }
            return sum;
        }
        /// <summary>
        /// 拿最后一个注入实现类（去掉IEnumerabl）
        /// </summary>
        /// <returns></returns>
        [HttpPost("test2")]
        public string test2()
        {
            return _userServices1.Test();
        }
    }
}
